package com.xmx.ndmallwxapi.controller;

import com.xmx.common.holder.LoginUserHolder;
import com.xmx.common.utils.R;
import com.xmx.ndmallwxapi.service.CartService;
import com.xmx.ndmallwxapi.vo.cart.CartAddVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/wx/cart")
public class CartController {
    @Resource
    CartService cartService;

    @Resource
    LoginUserHolder userHolder;

    @GetMapping("/goodscount")
    public R goodscount(){
        // TODO:  获取用户id
        Integer uid = userHolder.getCurrentUser().getId();
        Integer countgood = cartService.countgood(uid);
        return R.ok().put("data",countgood);
    }

    @PostMapping("/fastadd")
    public R fastadd(@RequestBody CartAddVo cartdata){
//      TODO:  判断是否登录||获取登录信息,假数据
//        Integer userId = 1;
        Integer userId = userHolder.getCurrentUser().getId();
        R fastadds = cartService.fastadds(userId, cartdata);
        return fastadds;
    }

    @GetMapping("/checkout")
    public R checkout( Integer cartId, Integer addressId, Integer couponId, Integer userCouponId, Integer grouponRulesId){
//        Integer userId = 1;
        Integer userId = userHolder.getCurrentUser().getId();
        R checkout = cartService.checkout(userId, cartId, addressId, couponId, userCouponId, grouponRulesId);
        return checkout;
    }
}
